/*
 * Created by JFormDesigner on Sun Jun 23 16:37:12 CST 2024
 */

package scct.chenhui.forms;

import scct.chenhui.dao.BrandDao;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author Administrator
 */
public class AddBrandDialog extends JDialog {
    public AddBrandDialog(Window owner) {
        super(owner);
        initComponents();
    }

    private void btnAdd(ActionEvent e) {
         String name=txtName.getText();
         String company=txtCompany.getText();
        BrandDao brandDao = new BrandDao();
        if(brandDao.addBrand(name, company))
        {
            JOptionPane.showMessageDialog(null,"成功添加一条记录");
            dispose();
        }
    }

    private void btnCancel(ActionEvent e) {
        // TODO add your code here
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        // Generated using JFormDesigner Evaluation license - hui chen
        label1 = new JLabel();
        txtName = new JTextField();
        label2 = new JLabel();
        txtCompany = new JTextField();
        btnAdd = new JButton();
        btnCancel = new JButton();

        //======== this ========
        setTitle("\u6dfb\u52a0\u54c1\u724c");
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u54c1\u724c\u540d\u79f0");
        contentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(70, 80), label1.getPreferredSize()));
        contentPane.add(txtName);
        txtName.setBounds(140, 70, 170, txtName.getPreferredSize().height);

        //---- label2 ----
        label2.setText("\u54c1\u724c\u5382\u5546");
        contentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(70, 135), label2.getPreferredSize()));
        contentPane.add(txtCompany);
        txtCompany.setBounds(140, 130, 170, txtCompany.getPreferredSize().height);

        //---- btnAdd ----
        btnAdd.setText("\u6dfb\u52a0");
        btnAdd.addActionListener(e -> {
			btnAdd(e);
		});
        contentPane.add(btnAdd);
        btnAdd.setBounds(new Rectangle(new Point(90, 205), btnAdd.getPreferredSize()));

        //---- btnCancel ----
        btnCancel.setText("\u53d6\u6d88");
        btnCancel.addActionListener(e -> btnCancel(e));
        contentPane.add(btnCancel);
        btnCancel.setBounds(new Rectangle(new Point(220, 205), btnCancel.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        setSize(410, 310);
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    // Generated using JFormDesigner Evaluation license - hui chen
    private JLabel label1;
    private JTextField txtName;
    private JLabel label2;
    private JTextField txtCompany;
    private JButton btnAdd;
    private JButton btnCancel;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
